// 给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度。

var lengthOfLongestSubstring = function (s) {
  if (!s) {
    return 0;
  }

  let length = s.length;
  let result = 1;

  const isTrue = (str) => {
    let isOk = true;
    let str_copy = "";
    let length = str.length;
    for (let i = 0; i < length; i++) {
      let stri = str.charAt(i);
      if (str_copy.includes(stri)) {
        isOk = false;
        break;
      } else {
        str_copy = str.slice(0, i + 1);
      }
    }
    return isOk;
  };

  for (let i = 0; i < length - result; i++) {
    for (let j = i + result; j < length; j++) {
      let str = s.slice(i, j + 1);
      if (!isTrue(str)) {
        break;
      }
      result = str.length;
    }
  }

  return result;
};

let str1 =
  "cabuadvavabc151151181cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg saavgacd xatdcvfavacxvbyatdyatgavdcavbdgcabuadvavabc  151151181cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg saavgacd xatdcvfavacxvbyatdyatgavdcavbdgcabuadvavabc  151151181cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg cabuadvavabc  151151181saavgacd xatdcvfavacxvbyatdyatgavdcavbdg saavgacd xatdcvfavacxvbyatdyatgavdcavbdg vZcbv huyfzadavuydbayvutdayugdahvghvvhgcghzvcvadvdvg vZcbv huyfzadavuydbayvutdayugdahvghvvhgcghzvcvadvdvg vZcbv huyfzadavuydbayvutdayugdahvghvvhgcghzvcvadvdvg";

let str2 = "abcabcbb";
console.time();
console.log(lengthOfLongestSubstring(str1));
console.timeEnd();
